import request from './request'

export function getRoles(){
  return request({
    url:'/roles',
    method:'GET'
  })
}

export function getRights(type){
  return request({
    url: `/rights/${type}`,
    method: 'GET'
  })
}

export function deleteRightOfRole(roleId,rightId){
  return request({
    url: `/roles/${roleId}/rights/${rightId}`,
    method: 'delete'
  })
}

export function addRole(data){
  return request({
    url: '/roles',
    method:'post',
    data:data,
  })
}

export function deleteRoleById(roleId){
  return request({
    url: `/roles/${roleId}`,
    method: 'delete'
  })
}

export function setRightsForRole(roleId,rids){
  return request({
    url: `/roles/${roleId}/rights`,
    method: 'POST',
    data:{
      rids,
    }
  })
}

export function editRole(id,data){
  return request({
    url: `roles/${id}`,
    method: 'put',
    data:data,
  })
}